<?php
session_start();
header('Content-type:text/html;charset=utf-8');
if(isset($_POST["login"]) && $_POST["login"] == "登陆")
{
    $user = $_POST["name-login"];
    $psw = $_POST["password-login"];
    if($user == "" || $psw == "")
    {
        echo "<script>alert('请输入用户名或密码！'); history.go(-1);</script>";
    }
    else
    {
        $link = mysqli_connect("localhost","root","123",'Dress', '3306');
        mysqli_query($link,"set names 'gbk'");
        $sql = "select username,password from user where username = '$user' and password = '$psw'";
        $result = mysqli_query($link,$sql);
        $num = mysqli_num_rows($result);
        if($num)
        {
            $_SESSION["user"]=$user;
            echo "<script>alert('登陆成功！'); window.location= 'index.php';</script>";
        }
        else
        {
            echo "<script>alert('用户名或密码不正确！');history.go(-1);</script>";
        }
    }
}
else
{
    echo "<script>alert('提交未成功！'); history.go(-1);</script>";
}

?>